package com.loubii.sunshineSchool.ui.avtivity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.loubii.sunshineSchool.R;
import com.loubii.sunshineSchool.httpRequest.HttpBin;
import retrofit2.Call;
import retrofit2.Response;


public class SSPassWordActivity extends AppCompatActivity {
    Button register;
    EditText oldPassword;
    EditText newPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_password);
        register=(Button)findViewById(R.id.btn_login);
        oldPassword=(EditText)findViewById(R.id.et_userName);
        newPassword=(EditText)findViewById(R.id.et_userRealName);
        ViewClick();
    }

    private void ViewClick() {
        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String opw = oldPassword.getText().toString();
                final String npw = newPassword.getText().toString();
                if (opw.isEmpty() || npw.isEmpty()) {
                    Toast.makeText(getApplicationContext(), "请输入完整~", Toast.LENGTH_LONG).show();
                    return;
                }
                HttpBin.changePassword(SSPassWordActivity.this, opw, npw, new HttpBin.ResponseListener<Boolean>() {
                    @Override
                    public void onResponse(Call<Boolean> call, Response<Boolean> response) {
                        if (response.body()) {
                            Toast.makeText(SSPassWordActivity.this, "修改密码成功~", Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(SSPassWordActivity.this, "原密码错误，请重新输入~", Toast.LENGTH_LONG).show();
                        }
                        oldPassword.setText("");
                        newPassword.setText("");
                    }

                    @Override
                    public void onFailure(Call<Boolean> call, Throwable t) {

                    }
                });
            }
        });
    }
}
